//-----------------------------------------------------------------------
// <copyright file="a_AgreeToUseDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_AgreeToUseDAOBase
    {
        #region Common methods
        public virtual a_AgreeToUse Createa_AgreeToUseFromReader(IDataReader reader)
        {
            a_AgreeToUse item = new a_AgreeToUse();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("AgreeID"))) item.AgreeID = (int)reader["AgreeID"];
                if (!reader.IsDBNull(reader.GetOrdinal("AgreeDate"))) item.AgreeDate = (DateTime)reader["AgreeDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("CookieID"))) item.CookieID = (string)reader["CookieID"];
                if (!reader.IsDBNull(reader.GetOrdinal("IP"))) item.IP = (string)reader["IP"];
                if (!reader.IsDBNull(reader.GetOrdinal("AgreeDocName"))) item.AgreeDocName = (string)reader["AgreeDocName"];
                if (!reader.IsDBNull(reader.GetOrdinal("OrderID"))) item.OrderID = (int)reader["OrderID"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("UserID"))) item.UserID = (int)reader["UserID"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsAgreeNewCustomers"))) item.IsAgreeNewCustomers = (bool)reader["IsAgreeNewCustomers"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsAgreeNewOrders"))) item.IsAgreeNewOrders = (bool)reader["IsAgreeNewOrders"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_AgreeToUse methods
            
        public virtual void Createa_AgreeToUse(a_AgreeToUse a_AgreeToUse)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_AgreeToUse_ins");
                
                database.AddInParameter(dbCommand, "@AgreeDate", DbType.DateTime, a_AgreeToUse.AgreeDate);
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_AgreeToUse.CookieID);
                database.AddInParameter(dbCommand, "@IP", DbType.AnsiString, a_AgreeToUse.IP);
                database.AddInParameter(dbCommand, "@AgreeDocName", DbType.AnsiString, a_AgreeToUse.AgreeDocName);
                database.AddInParameter(dbCommand, "@OrderID", DbType.Int32, a_AgreeToUse.OrderID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_AgreeToUse.DomainID);
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_AgreeToUse.UserID);
                database.AddInParameter(dbCommand, "@IsAgreeNewCustomers", DbType.Boolean, a_AgreeToUse.IsAgreeNewCustomers);
                database.AddInParameter(dbCommand, "@IsAgreeNewOrders", DbType.Boolean, a_AgreeToUse.IsAgreeNewOrders);
                database.AddOutParameter(dbCommand, "@AgreeID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_AgreeToUse.AgreeID = (int)database.GetParameterValue(dbCommand, "@AgreeID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_AgreeToUse methods
        
        public virtual void Updatea_AgreeToUse(a_AgreeToUse a_AgreeToUse)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_AgreeToUse_upd");            
                
                database.AddInParameter(dbCommand, "@AgreeID", DbType.Int32, a_AgreeToUse.AgreeID);
                database.AddInParameter(dbCommand, "@AgreeDate", DbType.DateTime, a_AgreeToUse.AgreeDate);
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_AgreeToUse.CookieID);
                database.AddInParameter(dbCommand, "@IP", DbType.AnsiString, a_AgreeToUse.IP);
                database.AddInParameter(dbCommand, "@AgreeDocName", DbType.AnsiString, a_AgreeToUse.AgreeDocName);
                database.AddInParameter(dbCommand, "@OrderID", DbType.Int32, a_AgreeToUse.OrderID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_AgreeToUse.DomainID);
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_AgreeToUse.UserID);
                database.AddInParameter(dbCommand, "@IsAgreeNewCustomers", DbType.Boolean, a_AgreeToUse.IsAgreeNewCustomers);
                database.AddInParameter(dbCommand, "@IsAgreeNewOrders", DbType.Boolean, a_AgreeToUse.IsAgreeNewOrders);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_AgreeToUse methods
        public virtual void Deletea_AgreeToUse(int agreeID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_AgreeToUse_del");
                
                database.AddInParameter(dbCommand, "@AgreeID", DbType.Int32, agreeID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_AgreeToUse methods
        
        public virtual a_AgreeToUse Geta_AgreeToUse(int agreeID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_AgreeToUse_sel");
                
                database.AddInParameter(dbCommand, "@AgreeID", DbType.Int32, agreeID);
                
                a_AgreeToUse a_AgreeToUse =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_AgreeToUse = Createa_AgreeToUseFromReader(reader);
                        reader.Close();
                    }
                }
                return a_AgreeToUse;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_AgreeToUseList methods
        public virtual a_AgreeToUseCollection Geta_AgreeToUseList(a_AgreeToUseColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_AgreeToUse_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_AgreeToUseCollection a_AgreeToUseCollection = new a_AgreeToUseCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_AgreeToUse a_AgreeToUse = Createa_AgreeToUseFromReader(reader);
                        a_AgreeToUseCollection.Add(a_AgreeToUse);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_AgreeToUseCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_AgreeToUseCollection Geta_AgreeToUseList(a_AgreeToUseColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_AgreeToUseList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}